package com.afinal.intelligencetrash.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.afinal.intelligencetrash.Model.bean.Message;
import com.afinal.intelligencetrash.R;
import com.afinal.intelligencetrash.ui.adapter.MessageListAdapter;
import com.afinal.intelligencetrash.ui.base.BaseFragment;
import com.afinal.intelligencetrash.ui.fragment.interfaces.FragmentView;
import com.afinal.intelligencetrash.utils.SimpleUtil;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by cyy on 17-10-12.
 */

public class InfromationTask extends BaseFragment implements FragmentView{

    private SwipeRefreshLayout refreshView;
    private RecyclerView messageList = null;

    private MessageListAdapter adapter = null;


    @Override
    protected boolean initView(View rootView, @Nullable Bundle savedInstanceState) {

        refreshView = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh);
        refreshView.setColorSchemeResources(R.color.colorPrimary);
        refreshView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                //reycleView刷新事件

                refreshView.setRefreshing(false);
            }
        });


        messageList = (RecyclerView) rootView.findViewById(R.id.messagelist);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        messageList.setLayoutManager(layoutManager);
        adapter = new MessageListAdapter();
        messageList.setAdapter(adapter);
        return true;
    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {
        List<Message> datelist = new LinkedList<>();
        for (int i = 1; i <= 5; i++){
            datelist.add(new Message("第"+i+"条消息:"+ SimpleUtil.generateRadomNum(100000, 999999), System.currentTimeMillis()));
        }
        adapter.setDateList(datelist);
    }



    @Override
    protected void dealloc() {

    }
    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_infromation_task;
    }
}
